(function(){
	var pub;
	if(!window.$b) window.$b = pub = function(uri) {
		if ( window == this || !this.init ){
			return new pub(uri);
		}
		return this.init(uri);
	}
	pub.fn = pub.prototype = {
		version: "2.0.1",
		bmsvc: Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Components.interfaces.nsINavBookmarksService),
		favisvc: Components.classes["@mozilla.org/browser/favicon-service;1"].getService(Components.interfaces.nsIFaviconService),
		init: function(uri) {
			try{
				this.uri=Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newURI(uri, null, null);
				//return this.uri
			}catch(err){
				return false;
			}
		},
		has:function (){
			if(!this.bmsvc.isBookmarked(this.uri)){
				return false;
			}else{
				return true;
			}
		},
		favicon:function (){
			try{
				return this.favisvc.getFaviconForPage(this.uri).spec;
			}catch(err){
				return this.favisvc.defaultFavicon.spec;
			}
		},
		get:function(){
			return this.bmsvc.getBookmarkIdsForURI(this.uri,{});
		},
		add:function(arg){
			if(this.has()){return false;}
			if(!arg) var arg={}
			if(!arg.title){arg.titel=null}
			return this.bmsvc.insertBookmark(this.bmsvc.unfiledBookmarksFolder,this.uri,-1,arg.title);
		},
		remove:function(){
			if(!this.has()){return false;}
			this.bmsvc.removeItem(this.get());
			return true;
		},
	}
})();
